﻿using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using HslCommunication.BasicFramework;
using HslCommunication.Core;
using HslCommunication.Core.IMessage;
using HslCommunication.Core.Net;
using HslCommunication.Reflection;
using Newtonsoft.Json;

namespace HslCommunication.Robot.EFORT
{
	/// <summary>
	/// 埃夫特机器人对应型号为ER7B-C10，此协议为旧版的定制版，报文未对齐的版本<br />
	/// The corresponding model of the efort robot is er7b-c10. This protocol is a customized version of the old version, and the message is not aligned
	/// </summary>
	// Token: 0x0200003B RID: 59
	public class ER7BC10Previous : NetworkDoubleBase, IRobotNet
	{
		/// <summary>
		/// 实例化一个默认的对象，并指定IP地址和端口号，端口号通常为8008<br />
		/// Instantiate a default object and specify the IP address and port number, usually 8008
		/// </summary>
		/// <param name="ipAddress">Ip地址</param>
		/// <param name="port">端口号</param>
		// Token: 0x060004E5 RID: 1253 RVA: 0x00013B8D File Offset: 0x00011D8D
		public ER7BC10Previous(string ipAddress, int port)
		{
			this.IpAddress = ipAddress;
			this.Port = port;
			base.ByteTransform = new RegularByteTransform();
			this.softIncrementCount = new SoftIncrementCount(65535L, 0L, 1);
		}

		/// <inheritdoc />
		// Token: 0x060004E6 RID: 1254 RVA: 0x00013BC7 File Offset: 0x00011DC7
		protected override INetMessage GetNewNetMessage()
		{
			return new EFORTMessagePrevious();
		}

		/// <summary>
		/// 获取发送的消息的命令<br />
		/// Gets the command to send the message
		/// </summary>
		/// <returns>字节数组命令</returns>
		// Token: 0x060004E7 RID: 1255 RVA: 0x00013BD0 File Offset: 0x00011DD0
		public byte[] GetReadCommand()
		{
			byte[] array = new byte[36];
			Encoding.ASCII.GetBytes("MessageHead").CopyTo(array, 0);
			BitConverter.GetBytes((ushort)array.Length).CopyTo(array, 15);
			BitConverter.GetBytes(1001).CopyTo(array, 17);
			BitConverter.GetBytes((ushort)this.softIncrementCount.GetCurrentValue()).CopyTo(array, 19);
			Encoding.ASCII.GetBytes("MessageTail").CopyTo(array, 21);
			return array;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.IRobotNet.Read(System.String)" />
		// Token: 0x060004E8 RID: 1256 RVA: 0x00013C59 File Offset: 0x00011E59
		[HslMqttApi(ApiTopic = "ReadRobotByte", Description = "Read the robot's original byte data information according to the address")]
		public OperateResult<byte[]> Read(string address)
		{
			return base.ReadFromCoreServer(this.GetReadCommand());
		}

		/// <inheritdoc cref="M:HslCommunication.Core.Net.IRobotNet.ReadString(System.String)" />
		// Token: 0x060004E9 RID: 1257 RVA: 0x00013C68 File Offset: 0x00011E68
		[HslMqttApi(ApiTopic = "ReadRobotString", Description = "Read the string data information of the robot based on the address")]
		public OperateResult<string> ReadString(string address)
		{
			OperateResult<EfortData> operateResult = this.ReadEfortData();
			bool flag = !operateResult.IsSuccess;
			OperateResult<string> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<string>(operateResult);
			}
			else
			{
				result = OperateResult.CreateSuccessResult<string>(JsonConvert.SerializeObject(operateResult.Content, 1));
			}
			return result;
		}

		/// <summary>
		/// 本机器人不支持该方法操作，将永远返回失败，无效的操作<br />
		/// This robot does not support this method operation, will always return failed, invalid operation
		/// </summary>
		/// <param name="address">指定的地址信息，有些机器人可能不支持</param>
		/// <param name="value">原始的字节数据信息</param>
		/// <returns>是否成功的写入</returns>
		// Token: 0x060004EA RID: 1258 RVA: 0x0000AC0F File Offset: 0x00008E0F
		[HslMqttApi(ApiTopic = "WriteRobotByte", Description = "This robot does not support this method operation, will always return failed, invalid operation")]
		public OperateResult Write(string address, byte[] value)
		{
			return new OperateResult(StringResources.Language.NotSupportedFunction);
		}

		/// <summary>
		/// 本机器人不支持该方法操作，将永远返回失败，无效的操作<br />
		/// This robot does not support this method operation, will always return failed, invalid operation
		/// </summary>
		/// <param name="address">指定的地址信息，有些机器人可能不支持</param>
		/// <param name="value">字符串的数据信息</param>
		/// <returns>是否成功的写入</returns>
		// Token: 0x060004EB RID: 1259 RVA: 0x0000AC0F File Offset: 0x00008E0F
		[HslMqttApi(ApiTopic = "WriteRobotString", Description = "This robot does not support this method operation, will always return failed, invalid operation")]
		public OperateResult Write(string address, string value)
		{
			return new OperateResult(StringResources.Language.NotSupportedFunction);
		}

		/// <summary>
		/// 读取机器人的详细信息<br />
		/// Read the details of the robot
		/// </summary>
		/// <returns>结果数据信息</returns>
		// Token: 0x060004EC RID: 1260 RVA: 0x00013CA8 File Offset: 0x00011EA8
		[HslMqttApi(Description = "Read the details of the robot")]
		public OperateResult<EfortData> ReadEfortData()
		{
			OperateResult<byte[]> operateResult = this.Read("");
			bool flag = !operateResult.IsSuccess;
			OperateResult<EfortData> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<EfortData>(operateResult);
			}
			else
			{
				result = EfortData.PraseFromPrevious(operateResult.Content);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Robot.EFORT.ER7BC10Previous.Read(System.String)" />
		// Token: 0x060004ED RID: 1261 RVA: 0x00013CE8 File Offset: 0x00011EE8
		[DebuggerStepThrough]
		public Task<OperateResult<byte[]>> ReadAsync(string address)
		{
			ER7BC10Previous.<ReadAsync>d__8 <ReadAsync>d__ = new ER7BC10Previous.<ReadAsync>d__8();
			<ReadAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadAsync>d__.<>4__this = this;
			<ReadAsync>d__.address = address;
			<ReadAsync>d__.<>1__state = -1;
			<ReadAsync>d__.<>t__builder.Start<ER7BC10Previous.<ReadAsync>d__8>(ref <ReadAsync>d__);
			return <ReadAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Robot.EFORT.ER7BC10Previous.ReadString(System.String)" />
		// Token: 0x060004EE RID: 1262 RVA: 0x00013D34 File Offset: 0x00011F34
		[DebuggerStepThrough]
		public Task<OperateResult<string>> ReadStringAsync(string address)
		{
			ER7BC10Previous.<ReadStringAsync>d__9 <ReadStringAsync>d__ = new ER7BC10Previous.<ReadStringAsync>d__9();
			<ReadStringAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<string>>.Create();
			<ReadStringAsync>d__.<>4__this = this;
			<ReadStringAsync>d__.address = address;
			<ReadStringAsync>d__.<>1__state = -1;
			<ReadStringAsync>d__.<>t__builder.Start<ER7BC10Previous.<ReadStringAsync>d__9>(ref <ReadStringAsync>d__);
			return <ReadStringAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Robot.EFORT.ER7BC10Previous.Write(System.String,System.Byte[])" />
		// Token: 0x060004EF RID: 1263 RVA: 0x00013D80 File Offset: 0x00011F80
		[DebuggerStepThrough]
		public Task<OperateResult> WriteAsync(string address, byte[] value)
		{
			ER7BC10Previous.<WriteAsync>d__10 <WriteAsync>d__ = new ER7BC10Previous.<WriteAsync>d__10();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ER7BC10Previous.<WriteAsync>d__10>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Robot.EFORT.ER7BC10Previous.Write(System.String,System.String)" />
		// Token: 0x060004F0 RID: 1264 RVA: 0x00013DD4 File Offset: 0x00011FD4
		[DebuggerStepThrough]
		public Task<OperateResult> WriteAsync(string address, string value)
		{
			ER7BC10Previous.<WriteAsync>d__11 <WriteAsync>d__ = new ER7BC10Previous.<WriteAsync>d__11();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<ER7BC10Previous.<WriteAsync>d__11>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Robot.EFORT.ER7BC10Previous.ReadEfortData" />
		// Token: 0x060004F1 RID: 1265 RVA: 0x00013E28 File Offset: 0x00012028
		[DebuggerStepThrough]
		public Task<OperateResult<EfortData>> ReadEfortDataAsync()
		{
			ER7BC10Previous.<ReadEfortDataAsync>d__12 <ReadEfortDataAsync>d__ = new ER7BC10Previous.<ReadEfortDataAsync>d__12();
			<ReadEfortDataAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<EfortData>>.Create();
			<ReadEfortDataAsync>d__.<>4__this = this;
			<ReadEfortDataAsync>d__.<>1__state = -1;
			<ReadEfortDataAsync>d__.<>t__builder.Start<ER7BC10Previous.<ReadEfortDataAsync>d__12>(ref <ReadEfortDataAsync>d__);
			return <ReadEfortDataAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x060004F2 RID: 1266 RVA: 0x00013E6C File Offset: 0x0001206C
		public override string ToString()
		{
			return string.Format("ER7BC10 Pre Robot[{0}:{1}]", this.IpAddress, this.Port);
		}

		// Token: 0x04000167 RID: 359
		private SoftIncrementCount softIncrementCount;
	}
}
